#hardware platform: FireBeetle-ESP8266from machine import Pin,I2C
from machine import ADCimport ssd1306

import dht
import machine
import time

d = dht.DHT11(machine.Pin(16))
i2c = I2C(scl=Pin(5), sda=Pin(4), freq=100000)  #Init i2c
adc0=ADC(0)  
lcd=ssd1306.SSD1306_I2C(128,64,i2c)  
led1=Pin(12,Pin.OUT)          #create LED object from pin2,Set Pin2 to output
led2=Pin(14,Pin.OUT)
led3=Pin(0,Pin.OUT)
led4=Pin(13,Pin.OUT)
fan=Pin(15,Pin.OUT)
while 1:
  d.measure()
  a=d.temperature() # eg. 23 (閹虹煰)
  b=d.humidity()    # eg. 41 (% RH)
  zidian={"WenDu":a,"ShiDu":b}
  print(zidian);
  ad=adc0.read()
  led1.value(1)              #turn off
  led2.value(1)              #turn off
  led3.value(1)              #turn off
  led4.value(1)              #turn off
  fan.value(1)
  time.sleep(0.5)
  led1.value(0)              #turn on
  led2.value(0)              #turn on
  led3.value(0)              #turn on
  led4.value(0)              #turn on
  fan.value(0)
  time.sleep(0.5);
  lcd.fill(0)
  lcd.text("Tianjin",0,0)                         #set "DFRobot" at (0,0)
  lcd.text("Agricultural",0,10)                       #set "chengdu" at (24,16)
  lcd.text("University",0,20)                        #set "123456" at (64,24)
  lcd.text("Tem:"+str(a)+"  hum:"+str(b),0,30)
  lcd.text("ADC:"+str(ad),0,40)
  lcd.show()


